package com.example.xiaoxueqixiangmu.jiemian;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xiaoxueqixiangmu.R;

import java.util.ArrayList;
import java.util.HashMap;


public class MyAdapter3 extends BaseAdapter {
    private Context context;
    private ArrayList<HashMap<String,String>> dataArray;

    public MyAdapter3(Context context , ArrayList<HashMap<String,String>> dataArray){
        this.context = context;
        this.dataArray = dataArray;
    }

    @Override
    public int getCount() {
        return dataArray.size();
    }

    @Override
    public Object getItem(int position) {
        return dataArray.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        View item = layoutInflater.inflate(R.layout.item_lv_chepiao3, null, false);
        TextView txtName = item.findViewById(R.id.txtName);
        TextView txtId = item.findViewById(R.id.txtId);
        TextView txtPhone = item.findViewById(R.id.txtPhone);
        ImageView cancel = item.findViewById(R.id.cancel);



        HashMap<String, String> hashMap = dataArray.get(position);

        txtName.setText(hashMap.get("txtName"));
        txtId.setText(hashMap.get("txtId"));
        txtPhone.setText(hashMap.get("txtPhone"));
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dataArray.remove(position);
                MyAdapter3.this.notifyDataSetChanged();
            }
        });

        return item;
    }
}
